package com.coderdream.chapter11.composite.a1;

import java.util.Iterator;
import java.util.Vector;

public class Directory extends Entry {

	private String name;

	private Vector directory = new Vector();

	public Directory(String name) {
		this.name = name;
	}

	@Override
	public String getName() {
		return this.name;
	}

	public Entry add(Entry entry) {
		this.directory.add(entry);
		entry.parent = this;

		return this;
	}

	@Override
	public int getSize() {
		int size = 0;

		Iterator it = directory.iterator();

		while (it.hasNext()) {
			Entry entry = (Entry) it.next();
			size += entry.getSize();
		}

		return size;
	}

	@Override
	protected void printList(String prefix) {
		System.out.println(prefix + "/" + this);
		Iterator it = this.directory.iterator();

		while (it.hasNext()) {
			Entry entry = (Entry) it.next();
			entry.printList(prefix + "/" + name);
		}
	}

}
